<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="950" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm"
				 label-width="110px"
				 label-position="left">
			<el-form-item label="服务卡名称" prop="card_name">
				<el-input v-model="form.card_name" placeholder="服务卡名称" clearable></el-input>
			</el-form-item>
			<el-form-item label="服务卡面" prop="card_pic">
				<sc-upload v-model="form.card_pic"
						   :completeUrl="form.card_pic_url" :limit="1"
						   title="服务卡面">
				</sc-upload>
				<div class="el-upload__tip text-red">
					大小1m以内，支持png、jpg、jpeg格式，尺寸建议 670*248
				</div>
			</el-form-item>
			<el-row>
				<el-col :span="11">
					<el-form-item label="选择商品" prop="card_product">
					</el-form-item>
				</el-col>
			</el-row>
			<el-table :data="form.card_product" style="width: 100%">
				<el-table-column label="序号" type="index" width="180"></el-table-column>
				<el-table-column label="商品ID" prop="product_id" width="100"></el-table-column>
				<el-table-column label="商品名称" prop="product_name" width="150"></el-table-column>
				<el-table-column label="销售价" prop="sale_price" width="150"></el-table-column>
				<el-table-column label="库存" prop="stock_qty" width="150"></el-table-column>
				<el-table-column label="有效期" prop="valid_date_text" width="140"></el-table-column>
				<el-table-column label="服务商名称" prop="provider_name" width="150"></el-table-column>
			</el-table>
			<el-row>
				<el-col :span="11">
					<el-form-item label=""><!--站位-->
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="备注" prop="remark">
				<el-input v-model="form.remark" placeholder="备注信息"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '新建商品',
				edit: '编辑商品',
				show: '查看'
			},
			visible: false,
			isSaveing: false,
			//表单数据
			form: {
				card_name: "",
				card_pic: "",
				card_pic_url: "",
				card_product: [],
			},
			//验证规则
			rules: {
				card_name: [
					{required: true, message: '请输入服务卡名称'}
				],
				card_pic: [
					{required: true, message: '请上传服务卡面'}
				],
				card_product: [
					{required: true, message: '请选择商品'}
				],
			},
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		//表单提交方法
		// submit() {
		// 	this.$refs.dialogForm.validate(async (valid) => {
		// 		if (valid) {
		// 			this.isSaveing = true;
		// 			this.$API['service_card.service_card'].store.post(this.form)
		// 				.then((res) => {
		// 					if (res.code == 0) {
		// 						this.$emit('success', this.form, this.mode)
		// 						this.$message.success("操作成功")
		// 					} else {
		// 						this.$alert(res.message, "提示", {type: 'error'})
		// 					}
		// 				})
		// 				.catch((msg) => {
		// 					this.$alert(msg, "提示", {type: 'error'})
		// 				})
		// 				.finally(() => {
		// 					this.isSaveing = false;
		// 				});
		// 		} else {
		// 			return false;
		// 		}
		// 	})
		// },
		//表单注入数据
		setData(data) {
			console.log(data, '+++++++++++++++');
			this.form.card_name = data.card_name
			this.form.card_pic = data.card_pic
			this.form.card_pic_url = data.card_pic_url
			this.form.card_product = data.card_product
			this.form.remark = data.remark
			// this.form.canadd_patient_user_num = data.canadd_patient_user_num
			//可以和上面一样单个注入，也可以像下面一样直接合并进去
			//Object.assign(this.form, data)
		}
	}
}
</script>

<style>
</style>
